package icu.yougan.youganblogbackend.controller;

import icu.yougan.youganblogbackend.common.Result;
import icu.yougan.youganblogbackend.model.Category;
import icu.yougan.youganblogbackend.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/list")
    public Result<List<Category>> list() {
        return categoryService.list();
    }

    @GetMapping("/{id}")
    public Result<Category> getById(@PathVariable Integer id) {
        return categoryService.getById(id);
    }

    @PostMapping
    public Result<Category> add(@RequestBody Category category) {
        return categoryService.add(category);
    }

    @PutMapping
    public Result<Category> update(@RequestBody Category category) {
        return categoryService.update(category);
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Integer id) {
        return categoryService.delete(id);
    }
}